package design;

import java.util.Stack;

public class leetCode155_MinStack {

    Stack<Integer> stack1 = new Stack<>();
    Stack<Integer> stack2 = new Stack<>();

    public void push(int val){
        stack1.push(val);
        if(stack2.isEmpty()){
            stack2.push(val);
        }else {
            Integer minNow = stack2.peek();
            if (val < minNow) {
                stack2.push(val);
            } else {
                stack2.push(minNow);
            }
        }
    }

    public void pop() {
        stack2.pop();
        stack1.pop();
    }

    public int top(){
        return stack1.peek();
    }

    public int getMin() {
        return stack2.peek();
    }

}
